package com.ssy.lingxi.purchase.api.enums.purchase;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 采购能力- 通用状态枚举
 *
 * @author lxc
 * @date 2022/2/25
 */
public enum StatusEnum {

    AGREE(1, "同意"),
    DISAGREE(2, "不同意"),
    NO(0, "否"),
    YES(1, "是"),
    ;
    private Integer state;
    private String name;

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    /**
     * 针对数据库储存Integer类型字段
     * @return
     */
    public String getName() {
        return LanguageHolder.getName(this.getClass(), this.state);
    }

    /**
     * 针对数据库储存String类型字段
     * @return
     */
    public String getCHName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    StatusEnum(Integer state, String name) {
        this.state = state;
        this.name = name;
    }

    public static String getName(String name){
        StatusEnum workEnum = Arrays.stream(StatusEnum.values()).filter(v -> v.getCHName().equals(name)).findAny().orElse(null);
        return null == workEnum ? "" : LanguageHolder.getName(StatusEnum.class, workEnum.getState());
    }

    public static String getName(Integer state){
        StatusEnum workEnum = Arrays.stream(StatusEnum.values()).filter(v -> v.getState().equals(state)).findAny().orElse(null);
        return null == workEnum ? "" : LanguageHolder.getName(StatusEnum.class, workEnum.getState());
    }
}
